//建造
import Global from "store"
cc.Class({
    extends: cc.Component,

    properties: {
        P_hammer: {
            default: null,
            type: cc.Node
        },
        P_water: {
            default: null,
            type: cc.Node
        },
        P_hammerLable: {
            default: null,
            type: cc.Label
        }
    },
    onLoad() {
        this.isBuild = false
        this.hammerCanMakeCount = 0;
        this.hammerMaxMackeCount = Global.cannonData.length;
        this.hammerLable()
        console.log(Global.cannonData.length)
    },
    hammerClick() {
        if (!this.isBuild) {
            if (this.hammerCanMakeCount < this.hammerMaxMackeCount) {
                let action = cc.sequence(cc.rotateTo(0.2, 90), cc.rotateTo(0.2, 0));
                this.P_hammer.runAction(action)
                this.hammerCanMakeCount++;
                this.hammerLable();
                this.isBuild = true
                this.P_water.height = 0
            }
        }
    },
    waterUpdate(dt) {
        if (!this.isBuild) {
            return
        }
        this.P_water.height += dt * 200
        if (this.P_water.height >= 133) {
            this.P_water.height = 133;
            this.isBuild = false
            Global.cannonBuild.cannonBuild(Global.cannonBuild.getCanMakeIndex())
            this.P_water.height = 0
        }
    },
    hammerLable() {
        this.P_hammerLable.string = `${this.hammerCanMakeCount}/${this.hammerMaxMackeCount}`
    },
    update(dt) {
        this.waterUpdate(dt)
    }
});